#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <aclconio.h>
#include <define.h>
#include <transact.h>
#include <tran.h>
#include <gds.h>
#include <sizes.h>
#include "ConfProto.h"
#include "tblutil.h"
#include <\SOFTPAY\Ver30\source\include\sizes.h>
#include <\SOFTPAY\Ver30\HostSrc\citisrc\citiids.h>
#include <\SOFTPAY\Ver30\HostSrc\cpacsrc\cpacids.h>
#include <confio.h>

#include <\SOFTPAY\Ver30\source\include\MHT.h>



static void *storeFromStruct;

static int recordNum;
void registerMHT(void *ptr)
{
	 storeFromStruct = ptr;
}

void *dealWithAddressBoundary(void*address);
int	inLoadMHTRecFromStruct (int inRecNumber, void *vdStruct)
{
	int inRet;
	char* tmp = (char*)vdStruct;

	registerMHT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inLoadConfRec(MHT_FILENAME, SIZE_MHT_REC, inRecNumber, vdStruct);

	recordNum = inRecNumber;
	return inRet;
}

void vdRestoreMHTRecFromStruct(void *vdStruct)
{
	registerMHT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	memcpy((char *) pvdGetMHTRec(), vdStruct, SIZE_MHT_REC);

}

void vdCopyMHTRecFromStruct(void *vdStruct)
{
	registerMHT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
		memcpy(vdStruct, (char *) pvdGetMHTRec(), SIZE_MHT_REC);

}

int	inSaveMHTRecFromStruct (int inRecNumber,  void *vdStruct)
{
	int inRet;

	registerMHT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(MHT_FILENAME, SIZE_MHT_REC, inRecNumber, (char *) vdStruct);

	return inRet;
}

int	inUpdateMHTRecFromStruct (void *vdStruct)
{
	int inRet;

	registerMHT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(MHT_FILENAME, SIZE_MHT_REC, recordNum, (char *) vdStruct);

	return inRet;
}

long lnGetSTANFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return lnGetSTAN();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MHT_REC*)vdStruct)->lnSTAN;
}

void vdSetSTANFromStruct(long lnSTAN, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetSTAN(lnSTAN);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((MHT_REC*)vdStruct)->lnSTAN = lnSTAN;
}

short shGetHostInvNumFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return shGetHostInvNum();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MHT_REC*)vdStruct)->shHostInvNum;
}

void vdSetHostInvNumFromStruct(short shHostInvNum, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetHostInvNum(shHostInvNum);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((MHT_REC*)vdStruct)->shHostInvNum = shHostInvNum;
}

long lnGetBatchNumFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return lnGetBatchNum();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MHT_REC*)vdStruct)->lnBatchNum;
}

void vdSetBatchNumFromStruct(long lnBatchNum, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetBatchNum(lnBatchNum);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((MHT_REC*)vdStruct)->lnBatchNum = lnBatchNum;
}

VS_BOOL fGetMustSettleFlagFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetMustSettleFlag();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MHT_REC*)vdStruct)->fMustSettleFlag;
}

void vdSetMustSettleFlagFromStruct(VS_BOOL fMustSettleFlag, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetMustSettleFlag(fMustSettleFlag);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((MHT_REC*)vdStruct)->fMustSettleFlag = fMustSettleFlag;
}

VS_BOOL fGetMustClearFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return fGetMustClear();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((MHT_REC*)vdStruct)->fMustClear;
}

void vdSetMustClearFromStruct(VS_BOOL fMustClear, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetMustClear(fMustClear);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((MHT_REC*)vdStruct)->fMustClear = fMustClear;
}

